#include <iostream>
using namespace std;

struct B
{
    virtual void f() const { cout << "B::f()" << endl; }
    void g() const { cout << "B::g()" << endl; }
};

struct D : B
{
    void f() const override { cout << "D::f()" << endl; }
    void g() const { cout << "D::g()" << endl; }
};

struct DD : D
{
    void f() { cout << "DD::f()" << endl; }
    void g() const { cout << "DD::g()" << endl; }
};

void call(const B &b)
{
    b.f();
    b.g();
}

int main()
{
    B b;
    D d;
    DD dd;
    call(b);
    call(d);
    call(dd);
    b.f();
    b.g();
    d.f();
    d.g();
    dd.f();
    dd.g();
    return 0;
};